/** 
 * Copyright (C), 2010-2012, AIYOU Software Co.,Ltd. ALL RIGHTS RESERVED. 
 * File name:AreaUtil.java
 * Version:1.0
 * Date:2012-1-2
 * Description: 
 * author:whh 
 */
package com.tietiao.common.util;

import java.util.List;
import java.util.Map;

import com.tietiao.common.bean.AreaBean;

public class AreaUtil {
	public static String ALL_CODE = "ALL";
	public static Map<String,List<AreaBean>> areaMap;
	
	/**
	 * 
	 * 功能：获得所有的省份信息
	 * @author: whh 
	 * @Date: 2012-1-2
	 * @return
	 */
	public static List<AreaBean> getProvince(){
		return areaMap.get(ALL_CODE); 
	}
	
	/**
	 * 功能：获得某个省份下所有城市信息
	 * @author: whh 
	 * @Date: 2012-1-2
	 *
	 * @param provinceName 省份代码
	 * @return
	 */
	public static List<AreaBean> getCity(String provCode){
		return areaMap.get(provCode);
	}
	
	/**
	 * 功能：通过省份代码获得省份信息
	 * @author: whh 
	 * @Date: 2012-1-2
	 * @param code 省代码
	 * @return
	 */
	public static String getProvinceNameByCode(String code){
		List<AreaBean> list = getProvince();
		for (AreaBean areaBean : list) {
			if(areaBean.getAreaCode().equals(code)){
				return areaBean.getAreaName();
			}
		}
		return null;
	}
	/**
	 * 
	 * 功能：获得某个省份下所有城市信息
	 * @author: whh 
	 * @Date: 2012-1-2
	 *
	 * @param provinceName 省份代码
	 * @return
	 */
	public static List<AreaBean> getCityByProv(String provName){
		List<AreaBean> citys = null; 
		List<AreaBean> list = getProvince();
		 if(list!=null && provName!=null){
			 for (AreaBean areaBean : list) {
				if(areaBean.getAreaName().equals(provName)){
					return areaMap.get(areaBean.getAreaCode());
				}
			}
		 }
		 return citys;
	}
}
